package MTT;
use Moose;
use namespace::autoclean;

use Catalyst::Runtime 5.80;

# Set flags and add plugins for the application
#
#         -Debug: activates the debug mode for very useful log messages
#   ConfigLoader: will load the configuration from a Config::General file in the
#                 application's home directory
# Static::Simple: will serve static files from the application's root
#                 directory

use MTT::Logger;


use Catalyst qw/
    -Debug
    ConfigLoader
    Static::Simple

	Authentication
	Authorization::Roles
	
	Session
	Session::Store::DBIC
	Session::State::Cookie
	Unicode::Encoding

	+MTT::Logger

/;


#	Unicode::Encoding
extends 'Catalyst';

our $VERSION = '0.01';
$VERSION = eval $VERSION;

use Log::Log4perl::Catalyst;

#__PACKAGE__->log( Log::Log4perl::Catalyst->new('logger.conf') );

# Configure the application.
#
# Note that settings in mtt.conf (or other external
# configuration file that you set up manually) take precedence
# over this when using ConfigLoader. Thus configuration
# details given here can function as a default configuration,
# with an external configuration file acting as an override for
# local deployment.
#__PACKAGE__->log( Log::Log4perl::Catalyst->new('logger.conf', autoflush => 1) );

__PACKAGE__->config(
	trace_location => '/trace'
);

__PACKAGE__->config(
    name => 'MTT',
    # Disable deprecated behavior needed by old applications
    disable_component_resolution_regex_fallback => 1,
	session => {flash_to_stash => 1},
	default_view => 'TT',
#	encoding => 'UTF-8',
);

__PACKAGE__->config(
	'Plugin::Logger' => {
		user_log => 'users',
		alarm_log => 'alarms'
	}
);

__PACKAGE__->config(
	static => {
		dirs => [
			'static',
			qr(images|css)
		],
	});

__PACKAGE__->config(
	'Plugin::Session' => {
		dbic_class => 'DBIC::Session',
		expires	   => 3600
	}
);

__PACKAGE__->config(
	'Plugin::Authentication' => {
		default_realm => 'users',
        users => {
            credential => {
                class 			   => 'Password',
				password_field 	   => 'password',
				password_type	   => 'self_check'
            },
            store => {
                class => 'DBIx::Class',
                role_relation => 'roles',
                role_field => 'role',
                use_userdata_from_session => '1',
                user_model => 'DBIC::User'
            }
		}
	}
);

__PACKAGE__->config(
	'View::JSON' => {
#    	allow_callback  => 1,    # defaults to 0
#        callback_param  => 'cb', # defaults to 'callback'
        expose_stash    => 'json_data', # defaults to everything
    },
);

__PACKAGE__->config(
	'View::PDF::Reuse' => {
		INCLUDE_PATH => __PACKAGE__->path_to('root', 'src', 'pdf')
    },
);

# Start the application
__PACKAGE__->setup();


=head1 NAME

MTT - Catalyst based application

=head1 SYNOPSIS

    script/mtt_server.pl

=head1 DESCRIPTION

[enter your description here]

=head1 SEE ALSO

L<MTT::Controller::Root>, L<Catalyst>

=head1 AUTHOR

Catalyst developer

=head1 LICENSE

This library is free software. You can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

1;
